unit Med_conf;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Mask, ExtCtrls, Buttons, Tools, GForm, bendri_conf, ComCtrls,
  Grids, DBGrids, Db, DBCtrls, DBClient, bendri;

type
  TMedConfigParam = class(TConfigParam)
    private
      //
    public
      //numatytos perkes
      MedPRastai: integer;        // Preke rastai
      MedPMediena: integer;       // Preke Mediena
      MedPParketas: integer;      // Preke Parketas
      MedPGrindjuostes: integer;  // Preke Plintusai

      // numatyti sandeliai
      MedSandelis: integer;      // Preke Parketas
      TarpSandelis: integer;  // Preke Plintusai
      ParkSandelis: integer;      // Preke Parketas
      PlintSandelis: integer;  // Preke Plintusai

      //Printeriai
      pDefPrinter: string;
      pLabelPrinter: string;

      constructor Create;
      procedure Free;
      procedure Save;
  end;

implementation

const
  cf_MedPRastai = 'MedPRastai';
  cf_MedPMediena = 'MedPMediena';
  cf_MedPParketas = 'MedPParketas';
  cf_MedPGrindjuostes = 'MedPGrindjuostes';
  cf_MedSandelis = 'MedSandelis';
  cf_TarpSandelis = 'TarpSandelis';
  cf_ParkSandelis = 'ParkSandelis';
  cf_PlintSandelis = 'PlintSandelis';
  c_DefPrinter = 'prDefPrinter';
  c_LabelPrinter = 'prLabelPrinter';

type
  TMedRegistry = class(TGamaRegistry)
    private
      procedure SetMedPRastai( v: integer );
      procedure SetMedPMediena( v: integer );
      procedure SetMedPParketas( v: integer );
      procedure SetMedPGrindjuostes( v: integer );

      procedure SetMedSandelis( v: integer );
      procedure SetTarpSandelis( v: integer );
      procedure SetParkSandelis( v: integer );
      procedure SetPlintSandelis( v: integer );

      procedure SetDefPrinter( v: string );
      procedure SetLabelPrinter( v: string );

      function  GetMedPRastai: integer;
      function  GetMedPMediena: integer;
      function  GetMedPParketas: integer;
      function  GetMedPGrindjuostes: integer;

      function  GetMedSandelis: integer;
      function  GetTarpSandelis: integer;
      function  GetParkSandelis: integer;
      function  GetPlintSandelis: integer;

      function  GetDefPrinter: string;
      function  GetLabelPrinter: string;

    public
      property MedPRastai: integer read GetMedPRastai write SetMedPRastai;
      property MedPMediena: integer read GetMedPMediena write SetMedPMediena;
      property MedPParketas: integer read GetMedPParketas write SetMedPParketas;
      property MedPGrindjuostes: integer read GetMedPGrindjuostes write SetMedPGrindjuostes;

      property MedSandelis: integer read GetMedSandelis write SetMedSandelis;
      property TarpSandelis: integer read GetTarpSandelis write SetTarpSandelis;
      property ParkSandelis: integer read GetParkSandelis write SetParkSandelis;
      property PlintSandelis: integer read GetPlintSandelis write SetPlintSandelis;

      property DefPrinter: string read GetDefPrinter write SetDefPrinter;
      property LabelPrinter: string read GetLabelPrinter write SetLabelPrinter;
  end;

// ******* GamaRegistry metodai **********
procedure TMedRegistry.SetMedPRastai; begin WriteIntegerValue(tgrMem, cf_MedPRastai, v) end;
procedure TMedRegistry.SetMedPMediena; begin WriteIntegerValue(tgrMem, cf_MedPMediena, v) end;
procedure TMedRegistry.SetMedPParketas; begin WriteIntegerValue(tgrMem, cf_MedPParketas, v) end;
procedure TMedRegistry.SetMedPGrindjuostes; begin WriteIntegerValue(tgrMem, cf_MedPGrindjuostes, v) end;

procedure TMedRegistry.SetMedSandelis; begin WriteIntegerValue(tgrMem, cf_MedSandelis, v) end;
procedure TMedRegistry.SetTarpSandelis; begin WriteIntegerValue(tgrMem, cf_TarpSandelis, v) end;
procedure TMedRegistry.SetParkSandelis; begin WriteIntegerValue(tgrMem, cf_ParkSandelis, v) end;
procedure TMedRegistry.SetPlintSandelis; begin WriteIntegerValue(tgrMem, cf_PlintSandelis, v) end;

procedure TMedRegistry.SetDefPrinter;  begin WriteStringValue(tgrRoot, c_DefPrinter, v) end;
procedure TMedRegistry.SetLabelPrinter;  begin WriteStringValue(tgrRoot, c_LabelPrinter, v) end;

function  TMedRegistry.GetMedPRastai; begin result := GetIntegerValue(tgrMem, cf_MedPRastai) end;
function  TMedRegistry.GetMedPMediena; begin result := GetIntegerValue(tgrMem, cf_MedPMediena) end;
function  TMedRegistry.GetMedPParketas; begin result := GetIntegerValue(tgrMem, cf_MedPParketas) end;
function  TMedRegistry.GetMedPGrindjuostes; begin result := GetIntegerValue(tgrMem, cf_MedPGrindjuostes) end;

function  TMedRegistry.GetMedSandelis; begin result := GetIntegerValue(tgrMem, cf_MedSandelis) end;
function  TMedRegistry.GetTarpSandelis; begin result := GetIntegerValue(tgrMem, cf_TarpSandelis) end;
function  TMedRegistry.GetParkSandelis; begin result := GetIntegerValue(tgrMem, cf_ParkSandelis) end;
function  TMedRegistry.GetPlintSandelis; begin result := GetIntegerValue(tgrMem, cf_PlintSandelis) end;

function  TMedRegistry.GetDefPrinter; begin result := GetStringValue(tgrRoot, c_DefPrinter) end;
function  TMedRegistry.GetLabelPrinter; begin result := GetStringValue(tgrRoot, c_LabelPrinter) end;

// ******** TEKAConfigParam metodai *********
constructor TMedConfigParam.Create;
var
  reg: TMedRegistry;
  i: integer;
  iSk: integer;
begin
  inherited Create;
  reg := TMedRegistry.Create;
  try
    if reg.MedPRastai = -1 then MedPRastai := 0 else MedPRastai := reg.MedPRastai;
    if reg.MedPMediena = -1 then MedPMediena := 0 else MedPMediena := reg.MedPMediena;
    if reg.MedPParketas = -1 then MedPParketas := 0 else MedPParketas := reg.MedPParketas;
    if reg.MedPGrindjuostes = -1 then MedPGrindjuostes := 0 else MedPGrindjuostes := reg.MedPGrindjuostes;

    if reg.MedSandelis = -1 then MedSandelis := 0 else MedSandelis := reg.MedSandelis;
    if reg.TarpSandelis = -1 then TarpSandelis := 0 else TarpSandelis := reg.TarpSandelis;
    if reg.ParkSandelis = -1 then ParkSandelis := 0 else ParkSandelis := reg.ParkSandelis;
    if reg.PlintSandelis = -1 then PlintSandelis := 0 else PlintSandelis := reg.PlintSandelis;

    pDefPrinter := reg.DefPrinter;
    pLabelPrinter := reg.LabelPrinter;

  finally
    reg.Free;
  end;
end;

procedure TMedConfigParam.Free;
begin
  if self <> nil then Save;
  inherited;
end;

procedure TMedConfigParam.Save;
var
  reg: TMedRegistry;
  i: integer;
  iSk: integer;
begin
  if not dmBendras.SQLConnectionGama.Connected then Exit;
  reg := TMedRegistry.Create;
  try
    if reg.MedPRastai <> self.MedPRastai then reg.MedPRastai := self.MedPRastai;
    if reg.MedPMediena <> self.MedPMediena then reg.MedPMediena := self.MedPMediena;
    if reg.MedPParketas <> self.MedPParketas then reg.MedPParketas := self.MedPParketas;
    if reg.MedPGrindjuostes <> self.MedPGrindjuostes then reg.MedPGrindjuostes := self.MedPGrindjuostes;

    if reg.MedSandelis <> self.MedSandelis then reg.MedSandelis := self.MedSandelis;
    if reg.TarpSandelis <> self.TarpSandelis then reg.TarpSandelis := self.TarpSandelis;
    if reg.ParkSandelis <> self.ParkSandelis then reg.ParkSandelis := self.ParkSandelis;
    if reg.PlintSandelis <> self.PlintSandelis then reg.PlintSandelis := self.PlintSandelis;

    if reg.DefPrinter <> self.pDefPrinter then reg.DefPrinter := self.pDefPrinter;
    if reg.LabelPrinter <> self.pLabelPrinter then reg.LabelPrinter := self.pLabelPrinter;
  finally
    reg.Free;
  end
end;

end.
